<template>
	<view :style="theme">
		<!-- 列表 -->
		<view class="num flex-cb">
			<view>累计积分：<text class="redColor">{{num}}</text></view>
			<view class="label flex-cc" @click="show = true">
				<text>{{tabName}}</text>
				<u-icon name="arrow-right" size="28rpx"></u-icon>
			</view>
		</view>
		<view class="box_list">
			<view class="box_title">积分明细</view>
			<view class="box_list_item" v-for="(item, index) in list" :key="index">
				<view class="box_flex flex-cb">
					<view class="left">
						<view>{{item.source}}</view>
						<view>{{item.createTime}}</view>
					</view>
					<view class="right" :class="type==1?'':'on'">{{item.type==1?'+':'-'}}{{item.integral}}</view>
				</view>
			</view>
		</view>
		<u-loadmore v-if="end && list.length >= 10" :status="status" line />
		<view v-if="list.length === 0" class="no-order">
			<image :src="imgHost+'/default_nodata.png'"></image>
			<view>暂无活动～</view>
		</view>
		<u-picker :defaultIndex="defaultIndex" :show="show" :columns="columns" keyName="name" @confirm="confirm"
			@cancel="show = false"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				columns: [
					[{
						name: '全部',
						id: ''
					}, {
						name: '收入',
						id: '1'
					}, {
						name: '支出',
						id: '2'
					}]
				],
				show: false,
				tabName: '全部',
				defaultIndex: [0],
				num: 0,
				index: '',
				page: 1,
				end: false,
				firstQueryTime: '',
				status: 'nomore',
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			confirm(e) {
				this.index = e.value[0].id
				this.tabName = e.value[0].name
				this.show = false
				this.firstQueryTime = this.$app.firstQueryTime()
				this.list = [];
				this.page = 1;
				this.end = false;
				this.getList()
			},
			getList() {
				this.$app.ajax({
					data: {
						pagination: {
							firstQueryTime: this.firstQueryTime,
							page: this.page,
							rows: 10
						},
						param: {
							venueId: this.venueId,
							memberId: this.userInfo.id,
							type: this.index
						}
					},
					api: this.$api.integralDetail()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.num = res.record.integralSum || 0
						if (!res.record || !res.record.resultList || res.record.resultList.length < 10) {
							this.end = true
						}
						if (res.record && res.record.resultList) {
							this.list = this.list.concat(res.record.resultList)
						}
					}
				}).catch(() => {})
			},
			reachBottom() {
				if (!this.end) {
					this.page += 1;
					this.getList();
				}
			},
			// 触底加载更多数据
			onReachBottom(e) {
				this.reachBottom()
			}

		}

	}
</script>
<style>
	page {
		background: #FFFFFF;
	}
</style>
<style scoped lang="scss">
	.num {
		font-weight: 400;
		color: #333333;
		font-size: 28rpx;
		height: 120rpx;
		line-height: 1.5;
		background: $bjColor;
		box-sizing: border-box;
		padding: 0 30rpx;
		.label {
			background: #FFFFFF;
			line-height: 54rpx;
			border-radius: 30rpx;
			padding: 0 30rpx;
			border: 1px solid #E5E5E5;
			color: #333333;
			font-size: 24rpx;
			text {
				margin-right: 10rpx;
			}
		}
	}
	.box_list {
		padding: 40rpx 30rpx 0;
		box-sizing: border-box;
		background-color: #fff;
	}

	.box_title {
		font-size: 32rpx;
		line-height: 40rpx;
		color: #000;
		font-weight: bolder;
		box-sizing: border-box;
		margin-bottom: 10rpx;
	}

	.box_list_item {
		padding: 30rpx 0;
		border-bottom: 1px solid #E5E5E5;
		box-sizing: border-box;
		margin-bottom: 24rpx;
		background: #ffffff;
		border-radius: 8rpx;
	}

	.left {
		font-size: 28rpx;
		line-height: 1.5;
		font-weight: 400;
		color: #222222;
	}

	.left view:last-of-type {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}

	.right {
		font-size: 32rpx;
		font-weight: bolder;
		color: #222222;
	}

	.right.on {
		color: $red;
	}
</style>
